package Utils;

import BasicDataStructures.ListNode;

import java.util.ArrayList;
import java.util.List;

public class ListUtils {
    public static ListNode generateList(int[] val) {
        if(val == null || val.length < 1) return null;
        ListNode head = new ListNode();
        ListNode curNode = head;
        int cur = 0;
        while(cur < val.length) {
            curNode.val = val[cur++];
            if(cur == val.length) break;
            curNode.next = new ListNode();
            curNode = curNode.next;
        }
        return head;
    }

    public static void printList(ListNode head) {
        while(head != null) {
            System.out.print(head.val + "->");
            head = head.next;
        }
        System.out.println("END");
    }

    public static List<List<Integer>> generateSegments(int[][] segs) {
        List<List<Integer>> res = new ArrayList<>();
        for(int[] seg: segs) {
            List<Integer> s = new ArrayList<>();
            s.add(seg[0]);
            s.add(seg[1]);
            res.add(s);
        }
        return res;
    }
}
